<template>
  <div>
    <h1>我的任务</h1>
    <table>
      <tr>
        <td>名称</td>

        <td>姓名</td>
        <td>文件</td>
        <td>请假理由</td>
        <td>请假类型</td>
        <td>开始时间</td>
        <td>结束时间</td>
        <td>状态</td>
      </tr>
      <tr v-for="i in list" :key="i">
        <td>{{ i.title }}</td>

        <td v-for="o in i.dilist" :key="o">{{ o.姓名 }}</td>
        <td v-for="o in i.dilist" :key="o">{{ o.文件 }}</td>
        <td v-for="o in i.dilist" :key="o">{{ o.请假理由 }}</td>
        <td v-for="o in i.dilist" :key="o">{{ o.请假类型 }}</td>
        <td v-for="o in i.dilist" :key="o">{{ o.开始时间 }}</td>
        <td v-for="o in i.dilist" :key="o">{{ o.结束时间 }}</td>
        <td>{{ change_k(i.state) }}
          <van-button @click="update_num(i.workid,i.userid,i.id,i.dilist)" v-if="i.state==4 && i.fist==0">修改</van-button>
        </td>

      </tr>
    </table>

    <van-popup v-model:show="show" style="width: 600px;height: 300px;font-size: 15px;padding: 10px">
      <p v-for="j in prams" :key="j">
        <van-field v-if="j.type=='field'" :label="j.lable" v-model="values[j.lable]"></van-field>
        <select name="" id="" v-if="j.type=='select'" v-model="values[j.lable]">
          <option :value="i.name" v-for="i in j.values" :key="i">{{ i.name }}</option>
        </select>

        <el-date-picker
            v-model="values[j.lable]"
            type="datetime"
            placeholder="开始时间"
            v-if="j.type=='datetime'"
        />

        <el-date-picker
            v-model="values[j.lable]"
            type="datetime"
            placeholder="结束时间"
            v-if="j.type=='datetime'"
        />
        <van-uploader v-if="j.type=='file'" :after-read="upload"></van-uploader>
      </p>
      <van-button @click="get_audit()">选择审核人</van-button>
      <el-dialog v-model="dialogTableVisible" title="Shipping address">
        <el-tree :data="data" :props="defaultProps" show-checkbox @check-change="hode_get" node-key="type"/>
        <van-button @click="show_flask"> 确定</van-button>
      </el-dialog>
      <van-button @click="submit">提交</van-button>
    </van-popup>
  </div>
</template>

<script>
export default {
  name: "my_task",
  data() {
    return {
      // 修改的
      prams: [],
      workid: [],
      values: [],
      dilist: [],
      dict: [],
      dialogTableVisible: false,
      // 原本的
      list: [],
      statelist: {1: '待审核', 2: '审核中', 3: '审核通过', 4: '审核失败'},
      show: false
    }
  },
  methods: {
    hode_get(data) {
      console.log(data)
      this.lists.push(data)
      if (data.type == 3) {
        this.node_id.push(data.id)
      }
      console.log(this.node_id)
    },
    submit() {
      // console.log(this.value1)
      console.log(this.values)
      this.values['userid'] = localStorage.getItem('userid')
      if (this.pic) {
        this.values['文件'] = this.pic
      }
      if (this.values['开始时间'] != null) {
        if (this.values['开始时间'] > this.values['结束时间']) {
          this.$toast.fail('时间不对请重新选择')
        }
      }
      console.log(this.values)
      let datas = []
      datas = this.values
      this.myaxios('http://localhost:5000/post_task', 'post', {'values': datas, 'node_id': this.node_id})
          .then(res => {
            console.log(res)
          })

    },
    show_flask() {
      this.dialogTableVisible = false
    },
    get_audit() {
      this.myaxios('http://localhost:5000/post_task', 'get', {})
          .then(res => {
            console.log(res)
            this.data = res.data.res
          })
      // 获取公司下的部门
      this.dialogTableVisible = true

    },
    upload: function (file) {
      let data = new FormData()
      data.append('file', file.file)
      const axios = this.axios.create({withCredentials: false})
      axios({url: 'http://localhost:5000/upload', method: 'post', data: data})
          .then(res => {
            console.log(res)
          })
    },
    get_qingj(workid) {
      this.myaxios('http://localhost:5000/get_worf', 'get', {'id': workid})
          .then(res => {
            console.log(res)
            console.log(res)
            console.log(res.data.list['params'])

            this.prams = JSON.parse(res.data.dict)
          })
    },


    update_num(workid, userid, id,dilist) {
      this.show = true
      this.get_qingj(workid)
      console.log(workid)
      console.log(userid)
      console.log(dilist)
      // this.values=dilist
      // this.values[0]=dilist
      // console.log(this.values)
      // console.log(this.dilist)

    },
    change_k(id) {
      return this.statelist[id]
    },
    // 获取数据
    get_my_task() {
      this.myaxios('http://localhost:5000/get_my_task', 'get', {'userid': localStorage.getItem('userid')})
          .then(res => {
            console.log(res)
            this.list = res.data.list

          })
    }
  },
  mounted() {
    this.get_my_task()
  }
}
</script>

<style scoped>

</style>
